package com.util;

public class PageTool {
    //当前页
    private int currentPageNo = 1;
    //总计数
    private int totalCount;
    //页大小
    private int pageSize = 5;
    //总页数
    private int totalPageCount = 1;
    private int nextPage;
    private int prePage;

    public int getCurrentPageNo() {
        return currentPageNo;
    }

    public void setCurrentPageNo(String currentPageNo) {
        if (currentPageNo == null) {
            currentPageNo = "1";
        }
        int currentPage = 1;
        try {
            currentPage = Integer.valueOf(currentPageNo);
        } catch (Exception e) {

        }
        if (currentPage > 0) {
            this.currentPageNo = currentPage;
        } else {
            this.currentPageNo = 1;
        }

    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        if (totalCount > 0) {
            this.totalCount = totalCount;
            calculate();
        }
    }

    //计算总页数
    private void calculate() {
        if (this.totalCount % this.pageSize == 0) {
            this.totalPageCount = this.totalCount / this.pageSize;
        } else {
            this.totalPageCount = this.totalCount / this.pageSize + 1;
        }
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getNextPage() {
        //当前页小于总页数
        if (this.currentPageNo < this.totalPageCount) {
            this.nextPage = this.currentPageNo + 1;
        } else {
            this.nextPage = this.totalPageCount;
        }
        return this.nextPage;
    }

    public void setNextPage(int nextPage) {
        this.nextPage = nextPage;
    }

    public int getPrePage() {

        if (this.currentPageNo > 1) {
            this.prePage = this.currentPageNo - 1;
        } else {
            this.prePage = 1;
        }
        return this.prePage;
    }

    public void setPrePage(int prePage) {
        this.prePage = prePage;
    }

    public int getTotalPageCount() {
        return totalPageCount;
    }

    public void setTotalPageCount(int totalPageCount) {
        this.totalPageCount = totalPageCount;
    }
}
